<!--受理订单列表-->
<style lang="less" scoped>
  .scroller-wrap {
    top: 119px;
  }
</style>


<template>
  <div class="contain">
    <div class="listhead-fix">
      <div class="m-sech-wrap mr20">
        <router-link :to="{path:'/search',query: { type: 'customDelivery', tabNo: this.type}}" class="m-sech-box displayflex"> 
          <i class="iconfont icon-search"></i>
          <div class="flex1 m-sech-ipt">
            <div class="txt">{{sechTxt || '输入业务单号名称或客户'}}</div>
          </div>
        </router-link>
      </div>

      <div class="lltab ft14">
        <tab bar-active-color="#77babd" defaultColor="#333333" active-color="#77babd" :line-width='2' v-model="tabNo">
          <tab-item @on-item-click="goLink(1)">高值订单</tab-item>
          <tab-item @on-item-click="goLink(2)">普耗订单</tab-item>
        </tab>
      </div>
    </div>


    <scroller lock-x scrollbar-y use-pullup height="-167" class='scroller-wrap' @on-pullup-loading="loadMore" v-if="items.length>0" :pullup-config="ScrollerConfig" ref="Scroller">
      <div class="acpt-list">
        <div class="acpt-list-wrap mb30" v-for="item in items">
          <div class="acpt-list-head cf">
            <span class="time f-l">{{item.BillNo}}</span>
            <em class="org f-r ft12" v-if="item.BillState == 'P01'" >待受理</em>
            <em class="org f-r ft12" v-if="item.BillState !== 'P01'" >{{item.BillState | billstate}}</em>
            <em class="org f-r ft12" v-if="item.BillState === 'N'" >待受理</em>
          </div>
          <div class="displayflex acpt-list-body">
            <i class="iconfont icon-cargo"></i>
            <div class="txt flex1" @click="gotoDet(item)">
              <p class="ft17">{{item.MedName}}</p>
              <p v-if="tabNo == 0">下单时间：{{item.AcceptanceDate | time}}</p>
              <p v-if="tabNo == 1">下单时间：{{item.BillDate | time}}</p>
              
              <p v-if="item.Address && item.Address !== ''">收货地址：{{item.Address}}</p>
              <p v-else>收货地址：{{item.Province | province}}{{item.City | city}}{{item.District | district}}</p>

              <p v-if="tabNo == 0">品种数：{{item.GoodsCount}}个</p>
              <p v-if="tabNo == 1">品种数：{{item.CountSum}}个</p>
            </div>
            <div class="acpt-list-btn">
              <!-- <div class="btn mb10" @click="gotoDet(item)" v-if="item.BillState == 'P01'">受理</div> -->
              <!-- <div class="btn" @click="goProgress()">进度</div> -->
            </div>
          </div>
        </div>
      </div>
      <div v-if="over" class="loader-over">没有更多记录了</div>
    </scroller>

    <div class="noDate_page" v-if="items.length<=0">
      <div class="noDate_icon"><i class="iconfont icon-null"></i></div>
      暂无数据！
    </div>

    <manage-footer :status='2'></manage-footer>
  </div>
</template>

<script>
import manageFooter from '@/components/core/footer/manage.footer.vue';
import { userInfo } from 'os';
export default {
  name:'acceptList',
  components: {
    manageFooter
  },
  data() {
    return {
      sechTxt:'',
      type:0,
      tabNo:0,
      PageIndex: 1,
      PageSize:4,
      items:[],
      totalRecords:'',
      over:false,
      billState:'',
      ScrollerConfig:{
        content: '上拉加载',
        downContent: '上拉加载',
        height: 0,
        loadingContent: '加载中...',
        upContent: '下拉刷新',
      },
    }
  },
  created(){
    this.sechTxt = sessionStorage.sechtxt;
    if(sessionStorage.getItem('ConsumableTab')){
        this.type = sessionStorage.getItem('ConsumableTab')*1;
        sessionStorage.removeItem('ConsumableTab')
      } else {
        this.type = 1;
      } 
  },
  watch: {
    type(n,o){
      this.$nextTick(function() {
        let title = '列表';
        if (this.type == 1) {
          title = `高值订单${title}`;
          this.getHVAccepted(1);
        }else if (this.type == 2) {
          title = `普耗订单${title}`;
          this.getAccepted(1);
        }
        document.title = title;
        this.tabNo = this.type -1;
      })
    }
  },
  mounted() {
    this.$nextTick(function() {
    })
  },
  methods: {
    loadMore () {
      if(this.tabNo == 0){
        this.getHVAccepted();
      } else {
        this.getAccepted();
      }
    },

    goLink(val){
      if(this.type !== val){
        this.type = val;
        sessionStorage.removeItem('sechtxt');
        this.sechTxt = '';
        this.over = false;
        this.items=[];
        this.PageIndex = 1;
        this.ScrollerConfig = {
          content: '上拉加载',
          downContent: '上拉加载',
          height: 0,
          loadingContent: '加载中...',
          upContent: '上拉加载',
        };
      }
    },

    getHVAccepted(type){
      let info = JSON.parse(localStorage.userinfo),
          query = {
            MedName:this.sechTxt,
            BillNo:this.sechTxt,
            BuyerGuid:info.StaffID,
            TenantGuid: info.TenantGUID,
            PageIndex: this.PageIndex,
            PageSize: this.PageSize,
            BeginDate: this.BeginDate,
            EndDate:this.EndDate,
            BillState: 'N',
          };
      if (sessionStorage.getItem('sechtxt')) {
        sessionStorage.removeItem('sechtxt');
      }
      
      this.Ajax.post('getTrsupplierhvpo',query).then((resp) => {
        if (resp.IsSuccess) {
          this.totalRecords = resp.TotalRecords;
          if(resp.Datas&&resp.Datas.length > 0){
            this.PageIndex++;
            this.items = this.items.concat(resp.Datas);
            this.ScrollControl();
          }
        } else {
          this.Toast({
              message: '列表为空，请稍后刷新',
          });
        }
      });
    },

    getAccepted(type){
      var info = JSON.parse(localStorage.userinfo),
          query = {
            TenantGuid:info.TenantGuid,
            MedName:this.sechTxt,
            BillNo:this.sechTxt,
            BillState: 'P02',
            BuyerGuid: info.StaffID,
            PageIndex: this.PageIndex,
            PageSize: this.PageSize,
            QueryType:1
          };
          console.log(query);
      if (sessionStorage.getItem('sechtxt')) {
        sessionStorage.removeItem('sechtxt');
      }
      this.Ajax.post('getAccepted',query).then((resp) =>{
        if (resp.IsSuccess) {
          this.totalRecords = resp.TotalRecords;
          if(resp.Datas&&resp.Datas.length > 0){
            this.PageIndex++;
            this.items = this.items.concat(resp.Datas);
            this.ScrollControl();
          }
        } else {
          this.Toast({
              message: '列表为空，请稍后刷新',
          });
        }
      });
    }, 

    gotoDet(value) {
      if(this.tabNo === 0){
        this.$router.push({
          path:'/order/consumablemateriaDetail',
          query:{
            id:value.Guid,
            type:1,
          }
        })
      }
      if(this.tabNo === 1){
        this.$router.push({
          path: '/order/acceptDetail',
          query:{
            id: value.Guid,
            Page: 'accept'
          }
        })
      }
    },

    goProgress() {
      this.$router.push({
        path: '/order/progress'
      });
    },
    ScrollControl(){
      if(this.totalRecords <= this.PageSize){
        this.ScrollerConfig.content = '';
        this.$nextTick(() => {
          this.$nextTick(() => {
            this.$refs.Scroller.disablePullup();
            this.over = true;
          });
        });
      }

      if(this.items.length > 0 && this.$refs.Scroller){
        this.$nextTick(() => {
          this.$nextTick(() => {
            this.$refs.Scroller.donePullup();
          });
        });
      }

      if (this.totalRecords == this.items.length) {
        this.$nextTick(() => {
          this.$nextTick(() => {
            this.$refs.Scroller.disablePullup();
            this.over = true;
          });
        });
      }
    }
  }
}
</script>